from django.db import models
from django.urls import reverse


# Create your models here.
class New(models.Model):
    news_id = models.AutoField(primary_key=True)
    news_title = models.CharField(max_length=20, verbose_name='新闻标题')
    news_summary = models.CharField(max_length=50, null=True, verbose_name='新闻简介')
    news_content = models.TextField(verbose_name='新闻内容')
    news_timestamp = models.DateTimeField(verbose_name='发布时间')
    news_like = models.IntegerField(verbose_name='点赞数')

    class Meta:
        managed=True
        db_table = 'meteor_new'

    def __str__(self):
        return self.news_title

    def get_absolute_url(self):
        return reverse('meteor:detail', kwargs={'pk': self.pk})


class NewLike(models.Model):
    news_title = models.CharField(max_length=20, verbose_name='新闻标题')
    news_summary = models.CharField(max_length=50, verbose_name='新闻简介')
    news_id = models.IntegerField(null=True)

    user = models.ForeignKey('keystone.User', on_delete=models.CASCADE,)